﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using log4net;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using System.IO;
using System.Collections;
using QuanLyNhaSach.Report;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace QuanLyNhaSach
{
    public partial class frmBc_DoanhThuBanHang : Form
    {
        public frmBc_DoanhThuBanHang()
        {
            InitializeComponent();
        }

        //Tao Parttern Seleton
        static frmBc_DoanhThuBanHang doituong = null;
        public static frmBc_DoanhThuBanHang TaoDoiTuong()
        {
            if (doituong == null)
                doituong = new frmBc_DoanhThuBanHang();
            return doituong;
        }

            #region "Khai bao bien"
        sv_QuanLyNhaSach.AdapterClient service = new sv_QuanLyNhaSach.AdapterClient();
        private ILog logger;
        DateTime tungay;
        DateTime denngay;
        DataSet ds_BCDoanhThu;
            #endregion



        private void frmBc_DoanhThuBanHang_Load(object sender, EventArgs e)
        {
            logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        }

        private void btn_Loc_Click(object sender, EventArgs e)
        {
            try
            {
                if (gvBC_DoanhThu.RowCount != 0)
                {
                    gvBC_DoanhThu.Rows.Clear();
                }
                tungay = dtpTuNgay.Value;
                denngay = dtpDenNgay.Value;
                ds_BCDoanhThu.ReadXml(new StringReader(service.BaoCaoDoanhThu(tungay,denngay)));
                if (ds_BCDoanhThu.Tables.Count != 0)
                {
                    DataTable tbl_BCDoanhThu = ds_BCDoanhThu.Tables[0];
                    for (int i = 0; i < tbl_BCDoanhThu.Rows.Count; i++)
                    {
                        tbl_BCDoanhThu.Rows[0][0] = tbl_BCDoanhThu.Rows[0][0].ToString().Replace(".0000", "");
                        tbl_BCDoanhThu.Rows[0][1] = tbl_BCDoanhThu.Rows[0][1].ToString().Replace(".0000", "");
                        tbl_BCDoanhThu.Rows[0][2] = tbl_BCDoanhThu.Rows[0][2].ToString().Replace(".0000", "");
                        tbl_BCDoanhThu.Rows[0][3] = tbl_BCDoanhThu.Rows[0][3].ToString().Replace(".0000", "");
                        tbl_BCDoanhThu.Rows[0][4] = tbl_BCDoanhThu.Rows[0][4].ToString().Replace(".0000", "");
                    }
                    gvBC_DoanhThu.DataSource = tbl_BCDoanhThu;
                }
                else
                {
                    MessageBox.Show("Không có thông tin dữ liệu", "Thông Báo", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error: " + ex.Message);
            }
        }
    }
}
